package main

import (
	"flag"
	"fmt"
	"os"
	"os/exec"
	"os/signal"
	"syscall"
	"time"
)

var mode = flag.String("mode", "", "which mode")

func init() {
	flag.Parse()
}
func main() {

	if *mode == "p" {
		a := exec.Command("./tsignal.out", "--mode", "c")
		a.Stdout = os.Stdout
		a.Start()
		fmt.Println("p:", os.Getpid())
		time.Sleep(time.Second * 99999)
	} else if *mode == "c" {
		fmt.Println("[OOXXOOXX], This is the child.")
		sigchan := make(chan os.Signal, 1)
		signal.Notify(sigchan, syscall.SIGTERM, syscall.SIGINT, syscall.SIGHUP)
		for {
			fmt.Println("c:", os.Getppid())
			a := <-sigchan
			fmt.Println("Child recv the signal", a.String())
		}
	} else {
		fmt.Println("Fuck")
	}
}
